package com.czwj.service.impl;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.transaction.Transactional;

import org.springframework.stereotype.Service;

import com.czwj.dao.CompanyMapper;
import com.czwj.dao.WarningValueMapper;
import com.czwj.entities.Company;
import com.czwj.entities.WarningValue;
import com.czwj.service.CompanyService;

@Service
public class CompanyServiceImpl implements CompanyService{
	@Resource
	CompanyMapper mapper;
	
	@Resource
	WarningValueMapper wmapper;
	
	@Override
	public int update(Company company){
		// TODO Auto-generated method stub
		return this.mapper.updateByPrimaryKeySelective(company);
	}
	
	@Transactional
	@Override
	public int insert(Company company){
		// TODO Auto-generated method stub
		int count = 0;
		count += this.mapper.insertSelective(company);
		WarningValue warningValue = new WarningValue();
		warningValue.setContent("进度");
		warningValue.setCompanyid(company.getId());
		warningValue.setPercent(90);
		count += wmapper.insertSelective(warningValue);
		WarningValue warningValue2 = new WarningValue();
		warningValue2.setContent("资金");
		warningValue2.setCompanyid(company.getId());
		warningValue2.setPercent(80);
		count += wmapper.insertSelective(warningValue2);
		return count;
	}
	
	@Override
	public int delete(int id){
		// TODO Auto-generated method stub
		return this.mapper.deleteByPrimaryKey(id);
	}
	
	@Override
	public List<Company> search(Map<String,Object> map){
		// TODO Auto-generated method stub
		return this.mapper.search(map);
	}
	
	@Override
	public int count(Map<String,Object> map){
		// TODO Auto-generated method stub
		return this.mapper.count(map);
	}
	
	@Override
	public Company findByName(String companyname){
		// TODO Auto-generated method stub
		return this.mapper.findByName(companyname);
	}
	
	@Override
	public int updateStatus(Map<String,Object> map){
		// TODO Auto-generated method stub
		return this.mapper.updateStatus(map);
	}
	
	@Override
	public Company selectByPrimaryKey(Integer companyid){
		// TODO Auto-generated method stub
		return this.mapper.selectByPrimaryKey(companyid);
	}
}
